set nocompatible
filetype on
filetype plugin on

call plug#begin('~/.config/nvim/plugged')
    Plug 'https://gitee.com/github-code-fork/json5.vim'
    Plug 'https://gitee.com/github-code-fork/vim-floaterm.git'
    Plug 'https://gitee.com/github-code-fork/vim-snazzy'
    Plug 'https://gitee.com/github-code-fork/vim-airline'
    Plug 'https://gitee.com/github-code-fork/bclose.vim'
    Plug 'https://github.com/theniceboy/joshuto.nvim'
    Plug 'preservim/nerdtree'
    Plug 'https://gitee.com/github-code-fork/vim-startify'
    Plug 'https://gitee.com/github-code-fork/nerdcommenter'
    Plug 'https://gitee.com/github-code-fork/vim-peekaboo'
    Plug 'https://gitee.com/github-code-fork/vim-gn'
    Plug 'https://gitee.com/github-code-fork/coc.nvim', {'branch': 'release'}
    Plug 'https://gitee.com/github-code-fork/vim-cpp-enhanced-highlight'
    Plug 'https://gitee.com/github-code-fork/vim-illuminate'
    Plug 'https://gitee.com/github-code-fork/auto-pairs'
    Plug 'https://gitee.com/github-code-fork/ack.vim'
    Plug 'https://gitee.com/github-code-fork/gruvbox'
    Plug 'https://gitee.com/github-code-fork/plantuml-previewer.vim' " apt install xdot
    Plug 'https://gitee.com/github-code-fork/open-browser.vim'
    Plug 'https://gitee.com/github-code-fork/plantuml-syntax'
    Plug 'https://gitee.com/github-code-fork/lazygit.nvim'
    Plug 'https://gitee.com/github-code-fork/markdown-preview.nvim'
    Plug 'Xuyuanp/nerdtree-git-plugin'
    Plug 'https://gitee.com/github-code-fork/vim-glsl'
    Plug 'nvim-treesitter/nvim-treesitter'
    Plug 'stevearc/dressing.nvim'
    Plug 'nvim-lua/plenary.nvim'
    Plug 'MunifTanjim/nui.nvim'
    Plug 'MeanderingProgrammer/render-markdown.nvim'
    Plug 'yetone/avante.nvim', { 'branch': 'main', 'do': 'make' }
    Plug 'hrsh7th/nvim-cmp'
    Plug 'nvim-tree/nvim-web-devicons' "or Plug 'echasnovski/mini.icons'
    Plug 'HakonHarnes/img-clip.nvim'
    Plug 'zbirenbaum/copilot.lua'
    Plug 'luochen1990/rainbow'
    " Plug 'github/copilot.vim'
call plug#end()

if has('win32')
  source $HOME/AppData/local/nvim/theme.vim
  source $HOME/AppData/local/nvim/coc.vim
else
  source $HOME/.config/nvim/theme.vim
  source $HOME/.config/nvim/coc.vim
endif

" vim-ack
nnoremap sa :Ack<cr>

" vim-airline
let g:airline#extensions#coc#enabled = 1
let g:airline#extensions#branch#enabled = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#show_buffers = 1
let g:airline#extensions#tabline#formatter = 'unique_tail'
let g:airline#extensions#tabline#tab_nr_type = 1
let g:airline#extensions#tabline#show_tab_nr = 1
let g:airline#extensions#tabline#fnametruncate = 16
let g:airline#extensions#tabline#fnamecollapse = 2
let g:airline#extensions#tabline#buffer_idx_mode = 1
let g:airline#extensions#tabline#buffer_nr_show = 0
let g:airline_powerline_fonts = 0
let g:airline_left_sep = ''
let g:airline_right_sep = ''

" vim-illuminate
let g:Illuminate_delay=500
highlight illuminatedWord guibg=#555555

" vim-nerdtree
map st :NERDTreeToggle<cr>

" vim-nerdcommenter
 let g:NERDSpaceDelims = 1
 let g:NERDCompactSexyComs = 1
 let g:NERDDefaultAlign = 'left'
 let g:NERDAltDelims_java = 1
 let g:NERDCommentEmptyLines = 1
 let g:NERDTrimTrailingWhitespace = 1
 let g:NERDToggleCheckAllLines = 1

" markdown-preview.nvim
" set to 1, nvim will open the preview window after entering the markdown buffer
" default: 0
let g:mkdp_auto_start = 0

" set to 1, the nvim will auto close current preview window when change
" from markdown buffer to another buffer
" default: 1
let g:mkdp_auto_close = 1

" set to 1, the vim will refresh markdown when save the buffer or
" leave from insert mode, default 0 is auto refresh markdown as you edit or
" move the cursor
" default: 0
let g:mkdp_refresh_slow = 0

" set to 1, the MarkdownPreview command can be use for all files,
" by default it can be use in markdown file
" default: 0
let g:mkdp_command_for_global = 0

" set to 1, preview server available to others in your network
" by default, the server listens on localhost (127.0.0.1)
" default: 0
let g:mkdp_open_to_the_world = 0

" use custom IP to open preview page
" useful when you work in remote vim and preview on local browser
" more detail see: https://github.com/iamcco/markdown-preview.nvim/pull/9
" default empty
let g:mkdp_open_ip = ''

" specify browser to open preview page
" for path with space
" valid: `/path/with\ space/xxx`
" invalid: `/path/with\\ space/xxx`
" default: ''
let g:mkdp_browser = ''

" set to 1, echo preview page url in command line when open preview page
" default is 0
let g:mkdp_echo_preview_url = 0

" a custom vim function name to open preview page
" this function will receive url as param
" default is empty
let g:mkdp_browserfunc = ''

" options for markdown render
" mkit: markdown-it options for render
" katex: katex options for math
" uml: markdown-it-plantuml options
" maid: mermaid options
" disable_sync_scroll: if disable sync scroll, default 0
" sync_scroll_type: 'middle', 'top' or 'relative', default value is 'middle'
"   middle: mean the cursor position alway show at the middle of the preview page
"   top: mean the vim top viewport alway show at the top of the preview page
"   relative: mean the cursor position alway show at the relative positon of the preview page
" hide_yaml_meta: if hide yaml metadata, default is 1
" sequence_diagrams: js-sequence-diagrams options
" content_editable: if enable content editable for preview page, default: v:false
" disable_filename: if disable filename header for preview page, default: 0
let g:mkdp_preview_options = {
    \ 'mkit': {},
    \ 'katex': {},
    \ 'uml': {},
    \ 'maid': {},
    \ 'disable_sync_scroll': 0,
    \ 'sync_scroll_type': 'middle',
    \ 'hide_yaml_meta': 1,
    \ 'sequence_diagrams': {},
    \ 'flowchart_diagrams': {},
    \ 'content_editable': v:false,
    \ 'disable_filename': 0,
    \ 'toc': {}
    \ }

" use a custom markdown style must be absolute path
" like '/Users/username/markdown.css' or expand('~/markdown.css')
let g:mkdp_markdown_css = ''

" use a custom highlight style must absolute path
" like '/Users/username/highlight.css' or expand('~/highlight.css')
let g:mkdp_highlight_css = ''

" use a custom port to start server or empty for random
let g:mkdp_port = ''

" preview page title
" ${name} will be replace with the file name
let g:mkdp_page_title = '「${name}」'

" recognized filetypes
" these filetypes will have MarkdownPreview... commands
let g:mkdp_filetypes = ['markdown']

" set default theme (dark or light)
" By default the theme is define according to the preferences of the system
let g:mkdp_theme = 'dark'

nmap <silent> <F8> <Plug>MarkdownPreview
imap <silent> <F8> <Plug>MarkdownPreview
nmap <silent> <F9> <Plug>MarkdownPreviewStop
imap <silent> <F9> <Plug>MarkdownPreviewStop

" vim-nerdtree-git-plugin
let g:NERDTreeGitStatusIndicatorMapCustom = {
    \ "Modified" : "✹",
    \ "Staged"   : "✚",
    \ "Untracked": "✭",
    \ "Renamed"  : "➜",
    \ "Unmerged" : "═",
    \ "Deleted"  : "✖",
    \ "Dirty"    : "✗",
    \ "Clean"    : "✔︎",
    \ "Unknown"  : "?"
\ }

" vim-floaterm
let g:floaterm_keymap_toggle = '<Leader>t'

" plantuml-previewer
nmap <silent> <F6> :PlantumlOpen<cr>
imap <silent> <F6> :PlantumlOpen<cr>
nmap <silent> <F7> :PlantumlSave<cr>
imap <silent> <F7> :PlantumlSave<cr>

" vim-lazygit
nnoremap <Leader>g :LazyGit<cr>

" ==================== joshuto.nvim ====================
nnoremap <Leader>f :Joshuto<cr>
let g:joshuto_floating_window_winblend = 0
let g:joshuto_floating_window_scaling_factor = 1.0
let g:joshuto_use_neovim_remote = 1 " for neovim-remote support

" deepseek
nnoremap <Leader>d :AvanteToggle<cr>

" rainbow
let g:rainbow_active = 1
